package com.suixuan.spring.test;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.stereotype.Service;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;

import com.suixuan.spring.entity.hbm.Menu;
import com.suixuan.spring.entity.hbm.U2;
import com.suixuan.spring.entity.security.Child1;
import com.suixuan.spring.service.hbm.IMenuService;
import com.suixuan.spring.service.hbm.IUService;
import com.suixuan.spring.service.impl.hbm.ChildCompServiceImpl;
import com.suixuan.spring.service.security.IChild1Service;
import com.suixuan.spring.service.security.IChild2Service;
import com.suixuan.spring.service.security.IUsersService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = [ "classpath:spring/applicationContext-*.xml" ])
@Service
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class Test1 extends AbstractTransactionalJUnit4SpringContextTests {

	@Resource
	private IUsersService usersServiceImpl;
	@Resource
	private IChild1Service child1ServiceImpl;
	@Resource
	private IChild2Service child2ServiceImpl;

	@Resource
	private IUService uServiceImpl;

	@Resource
	private IMenuService menuServiceImpl;

	@Resource
	private ChildCompServiceImpl childCompServiceImpl;

	@Test
	public void test() throws Exception {
		// userChild();

		// Users u = this.usersServiceImpl.findById(1L);
		//
		// System.out.println(u.getUsername());
		//
		// System.out.println(((Child1)u).getChild1());

		// this.saveU();

		def x = [2];
		def y = "xyz";

		println(this.childCompServiceImpl.say("张三"));
	}

	private void saveU() {
		U2 u2 = new U2();
		u2.setUsername("张三");
		u2.setPassword("password");

		u2.setCardId("c id");

		Menu menu = new Menu();
		menu.setName("name");
		menu.setUrl("url");
		u2.getMenus().add(menu);

		this.uServiceImpl.save(u2);
	}

	private void updateU() {
	}

	private void userChild() {
		Child1 c = new Child1();
		c.setUsername("张三");
		c.setPassword("password");
		c.setChild1("child1");
		this.child1ServiceImpl.save(c);
	}

	public static void main(String[] args) {
		def t = new Test1();
		def s =new StringBuilder();

		s << "append";

		println s;

		def d = [];
		"1.23".replaceAll(/\d+/) { d << it; };

		println d;

		List<String> a = new ArrayList<String>();

		a << "a";


		//println a;

		def x = t.&upper;

		a.each {x};
		
		
		println a;
		
		
		println t.&dounum(2);
	}


	def upper = { s->
		//println s;
		s.length;
	}
	
	def dounum = {
		it * 2;
	}
}
